﻿using System;
using System.Windows;
#if WPF
using System.Windows.Controls;
using System.Windows.Shapes;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Data;
using Windows.Foundation;
#endif

namespace Eternal.DataVisualization
{
    public class RangeColumnSeries : StockType
    {
        protected internal override void OnDrawSegment()
        {
            base.OnDrawSegment();
            if (XAxis != null && YAxis != null)
            {
                SegmentPanel.Children.Clear();

                for (var i = (int)Math.Floor(XAxis.Start); i <= (int)Math.Ceiling(XAxis.End); i++)
                {
                    var segmentDistance = new SegmentDistance { Delta = 0.0, Start = -0.4, End = 0.4 };
                    var segStart = segmentDistance.Start;
                    var segEnd = segmentDistance.End;

                    var rectangle = new Rectangle();

                    SegmentPanel.Children.Add(rectangle);

                    ApplyBrush(rectangle, i);

                    var value1 = new Point(i + segStart, Convert.ToDouble(ActualHigh[i]));
                    var value2 = new Point(i + segEnd, ActualLow[i]);
                    var center = new Point(i, Convert.ToDouble(ActualLow[i]));
                    var rect = new Rect(new Point(ValueToCoordianteXAxis(value1.X), ValueToCoordianteYAxis(value1.Y)), new Point(ValueToCoordianteXAxis(value2.X), ValueToCoordianteYAxis(value2.Y)));

                    rectangle.Width = rect.Width;
                    rectangle.Height = rect.Height;
                    rectangle.SetValue(Canvas.LeftProperty, rect.Left);
                    rectangle.SetValue(Canvas.TopProperty, rect.Top);
                }
            }
        }

    }
}
